<template>
	<view class="content">
		<f-navbar title="修改昵称" fontColor="#333" fontSize="34" bgColor="#fff">
			<view class="u-flex" slot="left">
				<van-icon name="arrow-left" color="#333" size="20"/>
			</view>
		</f-navbar>
		<view class="contentbox">
			<view class="content_btn" @click="submit">确定</view>
			<view class="nicknamebox">
				<input placeholder="请输入昵称" @input="onnickname" class="name_input" :value="name" type="text" maxlength="20">
				<view class="closeicon" @click="closebtn">
					<image class="closeimg" src="https://yuanchubao.oss-cn-beijing.aliyuncs.com/closeicon.png" mode=""></image>
				</view>
			</view>
			<view class="toastinfo">4-20个字符, 可由中英文、数字、“_”、“-” 组成</view>
		</view>
		
	</view>
</template>

<script>
	import fNavbar from '@/uni_modules/f-navbar/components/f-navbar/f-navbar.vue';
	import {setUserInfo} from '../../../utils/app.js'
	export default {
		components: {
			fNavbar
		},
		data() {
			return {
				name:''
			}
		},
		onLoad(options) {
			console.log(options);
			this.name = options.name
		},
		methods:{
			// 确定按钮
			submit(){
				if(this.name!==''){
					setUserInfo({
						fields:this.name,
						type:1
					}).then(res => {
						console.log(res);		
						if(res.code==1){
							var pages = getCurrentPages();
							var prevPage = pages[pages.length - 2]; //上一个页面
							console.log(prevPage);
							// prevPage.setData({
							//      userdata: {
							//        name:this.name
							//      }
							//    })
							   prevPage.$vm.getList()
							   uni.navigateBack({//返回
							     delta: 1
							   })
						} else {
							uni.showToast({
								title:res.info,
								icon:'none'
							})
						}
					})


				} else {
					uni.showToast({
						title:'请输入昵称',
						icon:'none'
					})
				}
			},
			// 输入昵称
			onnickname(e){
				// console.log(e.detail.value);
				this.name = e.detail.value
			},
			// 清楚输入的内容
			closebtn(){
				this.name= ''
			},
		}
		}
</script>

<style>
	page{
		background: #eee;
	}
	.content_btn{
		font-size: 24rpx;
		font-family: Hiragino Sans GB;
		font-weight: normal;
		color: #333333;
		display: flex;
		justify-content: flex-end;
		margin-right: 31rpx;
		margin-top: 14rpx;
		
	}
	.nicknamebox{
		width: 100%;
		height: 110rpx;
		background: #FFFFFF;
		margin-top: 20rpx;
		display: flex;
		align-items: center;
		justify-content: space-between;
	}
	.name_input{
		margin-left: 32rpx;
		font-size: 28rpx;
		font-family: Hiragino Sans GB;
		font-weight: normal;
		width: 80%;
	}
	.closeicon{
		width: 34rpx;
		height: 34rpx;
		margin-right: 32rpx;
		/* background: #000; */
		
	}
	.closeimg{
		width: 100%;
		height: 100%;
	}
	.toastinfo{

		font-size: 24rpx;
		color: #bbb;
		margin-left: 32rpx;
		margin-top: 16rpx;
	}
</style>